package view;
import java.rmi.RemoteException;

import controller.FirewallSession;

/**
 * Class is responsible for system initialization:
 * 		set initial status of system parameters.
 * 		initialize classes that their instances supposed to be allocated from the GUI run starting. 
 */
public class Initialization 
{
	/**
	 * C'tor -
	 * set initial status of system parameters:
	 * 		user mode 	- Expert/Standart
	 * 		logger mode	- turned on/off
	 * 		FW mode		- turned on/off
	 * 		FW status	- read-write/read only 
	 * initialize classes that their instances supposed to be allocated from the GUI run starting.
	 * 		Help		- help diplay
	 * 		Error		- errors list 
	 * 		Status Bar	- statuses that are displayed in each window
	 * 		Main		- the initial FW window with main menu
	 * @param ui - the controller for the system actions 
	 */
	public Initialization(FirewallSession ui)
	{	
		/* Statuses treatment */
		/* Check if user is expert/standart */
		try {
			if(ui.isExpert())
			{
				Settings.userMode = UserMode.ADVANCED;
			}
			else
			{
				Settings.userMode = UserMode.STANDART;
			}
		} catch (RemoteException e){
			ErrorFrame.AddError("RMI connenction problem: user status is undefined. " +
								"Standart user assumption", null);
		}
		
		/* Check if logger is on/off */
		try {
			StatusBar.loggerOn = ui.isLogEnabled();
		} catch (RemoteException e){
			ErrorFrame.AddError("RMI connenction problem: logger status is undefined. " +
								"Logger turned on assumption", null);
		}
		
		/* Check if FW is read-write/read only */
		try {
			StatusBar.isWrite = ui.isReadWrite();
		} catch (RemoteException e){
			ErrorFrame.AddError("RMI connenction problem: FW status is undefined. " +
								"FW writable status assumption", null);
		}

		/* Check if FW is on/off */
		try {
			StatusBar.fwTurnedOn = ui.isOn();
		} catch (Exception e){
			ErrorFrame.AddError("RMI connenction problem: FW status is undefined. " +
								"FW turned on assumption", null);
		}
		
		/* Always working windows initialization */
		ErrorFrame.getInctance();
		HelpFrame.getInctance();
		
		/* Timers initialization */
		StatusBar.getInstance(ui);
		
		/* Get main frame instance */
		MainFrame frame = MainFrame.getInstance(ui);
		/* Display the frame */
		frame.setVisible(true);
	}
}
